package com.exercise.cp;

import com.exercise.cp.domain.Person;
import com.exercise.cp.service.UserService;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Author 楠梦さま
 * @Created by 2021年11月17日  21:34
 */
public class test1 extends BaseTest {

    public static void goShow(UserService userService){
        userService.show();
    }

    /***
     * 54545
     */
    @Test
    public void test11(){
        new Thread(() -> {
            System.out.println("测试1启动..."+Thread.currentThread().getName());
        }).start();

    }

    @Test
    public void test12(){
        goShow(()->{
            System.out.println("lambda:打印show方法");
        });

        goShow(new UserService() {
            @Override
            public void show() {
                System.out.println("匿名内部类：打印show方法");
            }
        });
    }

    @Test
    public void test13(){
        List<Person> personList= new ArrayList<>();
        personList.add(new Person("八重樱",8,true));
        personList.add(new Person("迪卢克",10,false));
        personList.add(new Person("刻晴",7,true));
        personList.add(new Person("温迪",17,false));

        Collections.sort(personList, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getAge()-o2.getAge();
            }
        });

        Collections.sort(personList,(Person p1,Person p2)->{
            return p2.getAge()-p1.getAge();
        });

        personList.forEach(e->{
            System.out.println(e);
        });
    }
}
